<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.prime.com.tr/ui">

    <ui:composition template="/template/DefaultTemplate.xhtml">

        <ui:define name="content">
            <br/>

            <h:form prependId="false">

                <h:panelGroup id="messagePanel" layout="block">
                    <h:messages errorStyle="color: red" infoStyle="color: green" layout="table"/>
                </h:panelGroup>
                <h:outputText escape="false" value="No planned reservations found" rendered="#{plannedReserveEntityController.items.rowCount == 0}"/>

                <h:outputLabel rendered="#{plannedReserveEntityController.items.rowCount>0}" value="Amount of #{batchEntityController.selected.product.productName} left for fulfillment : #{batchEntityController.selected.amountLeftForFulfilment} Cases" for="Completed Goods Location Selection" />


                <p:panel toggleable="true" id="plannedReserveList" header="Planned Reservations" rendered="#{plannedReserveEntityController.items.rowCount > 0}">
                    <p:dataTable value="#{plannedReserveEntityController.plannedReservationsByProductItems}" 
                                 var="item"  
                                 style="table-layout:fixed" paginator="true" rows="10"  
                                 paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
                                 rowsPerPageTemplate="5,10,15">  
                        <p:column filterBy="#{item.id}">
                            <f:facet name="header">
                                <h:outputText value="Planned Reservation #"/>
                            </f:facet>
                            <h:outputText value="#{item.id}"/>
                        </p:column>

                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="Sales Order #"/>
                            </f:facet>
                            <h:outputText value="#{item.salesOrder.id}"/>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="Fulfilment Date"/>
                            </f:facet>
                            <h:outputText value="#{item.monthOfProduction}/#{item.yearOfProduction}"/>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="Product Name"/>
                            </f:facet>
                            <h:outputText value="#{item.product.productName}"/>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="Quantity"/>
                            </f:facet>
                            <h:outputText value="#{item.quantity}"/>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="Amount Fulfilled"/>
                            </f:facet>
                            <h:outputText value="#{item.amountFulfilled}"/>
                        </p:column>
                        <p:column>
                            <h:form>
                            <p:spinner id="spinner"  value="#{batchEntityController.fulfilledCases}" max="#{batchEntityController.selected.amountLeftForFulfilment}" min="0"/>
                            <p:commandButton ajax="false" value="Fulfil" update="plannedReserveList" action="#{batchEntityController.fulfilPlannedReservation}">
                                <f:setPropertyActionListener value="#{item}" target="#{batchEntityController.plannedReserve}"/>
                            </p:commandButton>
                            </h:form>
                        </p:column>

                    </p:dataTable>


                </p:panel>
                <p:commandButton  ajax="false" value="Next" action="/entities/inventoryEntity/CreateCG?faces-redirect=true"/>

            </h:form>

        </ui:define>
    </ui:composition>

</html>
